<template>
	<view class="mine-evaluate-list">

		<fixed>
			<view class="flex-warp fill-base pd-lg">
				<view @tap.stop="handerTabChange(index)" class="common-btn flex-center mr-md f-caption c-base radius-4"
					:style="{background:activeIndex==index?primaryColor:''}" v-for="(item,index) in tabList"
					:key="index">
					{{item.title}} ({{item.number}})
				</view>
			</view>
		</fixed>

		<view class="flex-warp fill-base pd-lg" :class="[{'b-1px-t':index!=0}]" v-for="(item,index) in list.data"
			:key="index">
			<image mode="aspectFill" lazy-load class="avatar sm radius" :src="item.user_info.avatarUrl"></image>
			<view class="flex-1 ml-lg">
				<view class="flex-between">
					<view class="f-paragraph c-title max-350 ellipsis">{{item.user_info.nickName}}</view>
					<view class="f-icontext c-caption">{{item.create_time}}</view>
				</view>
				<view class="flex-warp">
					<i class="iconfont icon-star-fill icon-font-color mr-sm"
						:style="{backgroundImage: aindex < item.star ? '-webkit-linear-gradient(90deg, #FDCD47, #FFC000)' : '-webkit-linear-gradient(90deg, #eee, #eee)'}"
						v-for="(aitem,aindex) in 5" :key="aindex"></i>
				</view>
				<view class="f-caption c-desc mt-md">
					<text decode="emsp" style="word-break:break-all;">{{item.text || '该用户没有填写评价哦'}}</text>
				</view>
				<view class="flex-warp mt-md" v-if="item.imgs && item.imgs.length > 0">
					<block v-for="(aitem,aindex) in item.imgs" :key="aindex">
						<view class="eva-img sm radius-10 rel" v-if="aindex < 3">
							<image @tap.stop="toPreviewImage(index,aindex)" mode="aspectFill" class="eva-img sm radius-10"
								:src="aitem">
							</image>
							<view class="more f-caption c-base abs" v-if="aindex == 2 && item.imgs.length > 3">
								+{{item.imgs.length - 3}}</view>
						</view>
					</block>
				</view>
			</view>
		</view>


		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
		</load-more>
		<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1"></abnor>
		<view class="space-footer"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				options: {},
				activeIndex: 0,
				tabList: [{
					id: 0,
					title: '全部',
					number: 0
				}, {
					id: 1,
					title: '好评',
					number: 0
				}, {
					id: 2,
					title: '差评',
					number: 0
				}],
				param: {
					page: 1,
					limit: 10
				},
				list: {
					data: []
				},
				loading: true,
				lockTap: false
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
			userInfo: state => state.user.userInfo,
		}),
		async onLoad(options) {
			this.options = options
			this.$util.showLoading()
			await this.initIndex()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return
			this.param.page = this.param.page + 1
			this.loading = true
			this.getList()
		},
		methods: {
			...mapActions(['getUserInfo']),
			async initIndex() {
				await this.getList()
			},
			initRefresh() {
				this.param.page = 1
				this.initIndex()
			},
			async getList() {
				let {
					list: oldList,
					tabList,
					activeIndex
				} = this
				let {
					id: goods_id,
					type
				} = this.options
				let {
					id: is_goods
				} = tabList[activeIndex]
				let param = Object.assign({}, this.param, {
					goods_id,
					type,
					is_goods
				});
				let newList = await this.$api.mine.goodsEvaluateList(param);
				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				let count = {
					0: 'all_count',
					1: 'good_count',
					2: 'bad_count'
				}
				for (let key in count) {
					this.tabList[key].number = newList[count[key]]
				}
				this.loading = false
				this.$util.hideAll()
			},
			handerTabChange(index) {
				this.activeIndex = index;
				this.$util.showLoading()
				this.param.page = 1
				this.list.data = []
				this.getList()
			},
			toPreviewImage(index, aindex) {
				let {
					imgs: urls
				} = this.list.data[index]
				this.$util.previewImage({
					current: urls[aindex],
					urls
				})
			},
		}
	}
</script>


<style lang="scss">
	.mine-evaluate-list {
		.common-btn {
			background: #CCCCCC;
		}
	}
</style>
